package sadmin

import (
	"errors"
	"github.com/astaxie/beego/orm"
	"shop/models/common"
)

type Faq struct {
	Id int
	Question string
	Answer string
}

func init()  {
	orm.RegisterModel(new(Faq))
}

func FaqAdd(q Faq) error {
	tt:=common.StrDelTrim(q.Answer)
	ttt:=common.StrDelTrim(q.Question)
	if tt==""||ttt==""{
		return errors.New(" can't be null")
	}
	o:=orm.NewOrm()
	_,er:=o.Insert(&q)
	return er
}

func FaqShow()([]Faq,error)  {
	o := orm.NewOrm()
	var c []Faq
	com := new(Faq)
	qs := o.QueryTable(com)
	_, err := qs.All(&c)
	return c, err
}

func FaqDel(id int) error {
	o:=orm.NewOrm()
	_,err:=o.Delete(&Faq{Id:id})
	return err
}